﻿@using Grand.Business.Core.Extensions
@using Grand.Business.Core.Interfaces.Common.Stores
@inject IStoreService StoreService
@inject IWorkContextAccessor workContextAccessor
@{
    var availableStores = (await StoreService.GetAllStores())
        .Select(x =>
        {
            //model
            var storeModel = new StoreModel
            {
                Id = x.Id,
                        Name = x.GetTranslation(y => y.Name, workContextAccessor.WorkContext.WorkingLanguage.Id),
                Shortcut = x.Shortcut
            };
            return storeModel;
        }).ToList();

    if (availableStores.Count > 1)
    {
        var returnUrl = Context?.Request?.GetEncodedPathAndQuery();

        <b-dropdown class="mr-2" text="@availableStores.FirstOrDefault(x => x.Id == workContextAccessor.WorkContext.CurrentStore.Id)?.Name">
            @foreach (var store in availableStores)
            {
                var className = store.Id == workContextAccessor.WorkContext.CurrentStore.Id ? "active" : "";
                <b-dropdown-item class="@className" href="@Url.RouteUrl("ChangeStore", new { shortcut = store.Shortcut, returnUrl })">
                    @store.Name
                </b-dropdown-item>
            }
        </b-dropdown>
    }
}